/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xiaohong.account.utils;

import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.account.pojo.AccountTbl;
import entity.Result;
import entity.StatusCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author fangjian
 */
public final class ExceptionUtil {

	//条件分页查询AccountTbl
	// 原方法调用被限流/降级/系统保护的时候调用
	public static Result<Page> findPageHandler (AccountTbl accountTbl, int page, int size, BlockException ex){
		System.out.println("发送了限流/降级/系统保护");
		ex.printStackTrace();
		return new Result<Page>(false, StatusCode.ERROR,"被降级了") ;
	}

	// 原方法调用被熔断的时候调用
	public static Result<Page> findPageFallback (AccountTbl accountTbl, int page, int size, Throwable throwable){
		System.out.println("发生了熔断");
		System.out.println(throwable);
		return new Result<Page>(false, StatusCode.ERROR,"被熔断了") ;
	}



	//分页搜索实现AccountTbl
	// 原方法调用被限流/降级/系统保护的时候调用
	public static Result<Page> findPageHandler (int page, int size, BlockException ex){
		System.out.println("发送了限流/降级/系统保护");
		ex.printStackTrace();
		return new Result<Page>(false, StatusCode.ERROR,"被降级了") ;
	}

	// 原方法调用被熔断的时候调用
	public static Result<Page> findPageFallback (int page, int size, Throwable throwable){
		System.out.println("发生了熔断");
		System.out.println(throwable);
		return new Result<Page>(false, StatusCode.ERROR,"被熔断了") ;
	}



	//多条件搜索AccountTbl数据
	// 原方法调用被限流/降级/系统保护的时候调用
	public static Result<List<AccountTbl>> findListHandler (AccountTbl accountTbl, BlockException ex){
		System.out.println("发送了限流/降级/系统保护");
		ex.printStackTrace();
		return new Result<List<AccountTbl>>(false, StatusCode.ERROR,"被降级了") ;
	}

	// 原方法调用被熔断的时候调用
	public static Result<List<AccountTbl>> findListFallback (AccountTbl accountTbl, Throwable throwable){
		System.out.println("发生了熔断");
		System.out.println(throwable);
		return new Result<List<AccountTbl>>(false, StatusCode.ERROR,"被熔断了") ;
	}


	// 根据Id删除accountTbl数据
	// 原方法调用被限流/降级/系统保护的时候调用
	public static Result deleteHandler (Integer id, BlockException ex){
		System.out.println("发送了限流/降级/系统保护");
		ex.printStackTrace();
		return new Result(false, StatusCode.ERROR,"被降级了") ;
	}

	// 原方法调用被熔断的时候调用
	public static Result deleteFallback (Integer id, Throwable throwable){
		System.out.println("发生了熔断");
		System.out.println(throwable);
		return new Result(false, StatusCode.ERROR,"被熔断了") ;
	}




	// 根据ID修改AccountTbl数据
	// 原方法调用被限流/降级/系统保护的时候调用
	public static Result updateHandler (AccountTbl accountTbl, Integer id, BlockException ex){
		System.out.println("发送了限流/降级/系统保护");
		ex.printStackTrace();
		return new Result(false, StatusCode.ERROR,"被降级了") ;
	}

	// 原方法调用被熔断的时候调用
	public static Result updateFallback (AccountTbl accountTbl, Integer id, Throwable throwable){
		System.out.println("发生了熔断");
		System.out.println(throwable);
		return new Result(false, StatusCode.ERROR,"被熔断了") ;
	}


	// 根据ID修改AccountTbl数据
	// 原方法调用被限流/降级/系统保护的时候调用
	public static Result addHandler (AccountTbl accountTbl, BlockException ex){
		System.out.println("发送了限流/降级/系统保护");
		ex.printStackTrace();
		return new Result(false, StatusCode.ERROR,"被降级了") ;
	}

	// 原方法调用被熔断的时候调用
	public static Result addFallback (AccountTbl accountTbl, Throwable throwable){
		System.out.println("发生了熔断");
		System.out.println(throwable);
		return new Result(false, StatusCode.ERROR,"被熔断了") ;
	}



	// 根据ID查询AccountTbl数据
	// 原方法调用被限流/降级/系统保护的时候调用
	public static Result<AccountTbl> findByIdHandler (AccountTbl accountTbl, BlockException ex){
		System.out.println("发送了限流/降级/系统保护");
		ex.printStackTrace();
		return new Result<AccountTbl>(false, StatusCode.ERROR,"被降级了") ;
	}

	// 原方法调用被熔断的时候调用
	public static Result<AccountTbl> findByIdFallback (AccountTbl accountTbl, Throwable throwable){
		System.out.println("发生了熔断");
		System.out.println(throwable);
		return new Result<AccountTbl>(false, StatusCode.ERROR,"被熔断了") ;
	}



	// 查询AccountTbl全部数据
	// 原方法调用被限流/降级/系统保护的时候调用
	public static Result<List<AccountTbl>> findAllHandler (BlockException ex){
		System.out.println("发送了限流/降级/系统保护");
		ex.printStackTrace();
		return new Result<List<AccountTbl>>(false, StatusCode.ERROR,"被降级了") ;
	}

	// 原方法调用被熔断的时候调用
	public static Result<List<AccountTbl>> findAllFallback (Throwable throwable){
		System.out.println("发生了熔断");
		System.out.println(throwable);
		return new Result<List<AccountTbl>>(false, StatusCode.ERROR,"被熔断了") ;
	}


}
